package match

func naive(txt, pat []rune) []int {
	n, m := len(txt), len(pat)
	result := []int{}
	for curr := 0; curr < n-m+1; curr++ {
		match := true
		for i, j := curr, 0; j < m; {
			if txt[i] != pat[j] {
				match = false
				break
			}
			j++
			i++
		}
		if match {
			result = append(result, curr)
		}
	}
	return result
}

// Naive 朴素字符匹配算法
func Naive(txt, pat string) []int {
	if len(pat) == 0 {
		return []int{}
	}
	return naive([]rune(txt), []rune(pat))
}
